<!-- saved from url=(0014)about:internet --><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<!-- Standard Head Part -->
<head>
<title>NUnit - ValueSource</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="en-US">
<link rel="stylesheet" type="text/css" href="nunit.css">
<link rel="shortcut icon" href="favicon.ico">
</head>
<!-- End Standard Head Part -->

<body>

<!-- Standard Header for NUnit.org -->
<div id="header">
  <a id="logo" href="http://www.nunit.org"><img src="img/logo.gif" alt="NUnit.org" title="NUnit.org"></a>
  <div id="nav">
    <a href="http://www.nunit.org">NUnit</a>
    <a class="active" href="index.html">Documentation</a>
  </div>
</div>
<!-- End of Header -->

<div id="content">

<script language="JavaScript" src="codeFuncs.js" ></script> <!-- Do it this way for IE -->

<h3>ValueSourceAttribute (NUnit 2.5)</h3>

<p><b>ValueSourceAttribute</b> is used on individual parameters of a test method to
identify a named source for the argument values to be supplied. The attribute has 
two public constructors.

<div class="code">
<pre>
ValueSourceAttribute(Type sourceType, string sourceName);
ValueSourceAttribute(string sourceName);
</pre>
</div>

<p>If <b>sourceType</b> is specified, it represents the class that provides
the data. It must have a default constructor.

<p>If <b>sourceType</b> is not specified, the class containing the test
method is used. NUnit will construct it using either the default constructor
or - if arguments are provided - the appropriate constructor for those 
arguments.

<p>The <b>sourceName</b>, represents the name of the source that will 
provide the arguments. It should have the following characteristics:
<ul>
<li>It may be a field, a non-indexed property or a method taking no arguments.
<li>It may be either an instance or a static member.
<li>It must return an IEnumerable or a type that implements IEnumerable.
<li>The individual items returned from the enumerator must be compatible
    with the type of the parameter on which the attribute appears.
</ul>

<h3>Order of Execution</h3>

<p>In NUnit 2.5, individual test cases are sorted alphabetically and executed in
   that order. With NUnit 2.5.1, the individual cases are not sorted, but are
   executed in the order in which NUnit discovers them. This order does <b>not</b>
   follow the lexical order of the attributes and will often vary between different
   compilers or different versions of the CLR.
   
<p>As a result, when <b>ValueSourceAttribute</b> appears multiple times on a 
   parameter or when other data-providing attributes are used in combination with 
   <b>ValueSourceAttribute</b>, the order of the arguments is undefined.

<p>However, when a single <b>ValueSourceAttribute</b> is used by itself, 
   the order of the arguments follows exactly the order in which the data 
   is returned from the source.
   
<h3>Note on Object Construction</h3>

<p>NUnit locates the test cases at the time the tests are loaded, creates
instances of each class with non-static sources and builds a list of 
tests to be executed. Each source object is only created once at this
time and is destroyed after all tests are loaded. 

<p>If the data source is in the test fixture itself, the object is created
using the appropriate constructor for the fixture parameters provided on
the <b>TestFixtureAttribute</b>, or
the default constructor if no parameters were specified. Since this object
is destroyed before the tests are run, no communication is possible between
these two phases - or between different runs - except through the parameters
themselves.

</div>

<!-- Submenu -->
<div id="subnav">
<ul>
<li><a href="index.html">NUnit 2.5.9</a></li>
<ul>
<li><a href="getStarted.html">Getting&nbsp;Started</a></li>
<li><a href="assertions.html">Assertions</a></li>
<li><a href="constraintModel.html">Constraints</a></li>
<li><a href="attributes.html">Attributes</a></li>
<ul>
<li><a href="category.html">Category</a></li>
<li><a href="combinatorial.html">Combinatorial</a></li>
<li><a href="culture.html">Culture</a></li>
<li><a href="datapoint.html">Datapoint(s)</a></li>
<li><a href="description.html">Description</a></li>
<li><a href="exception.html">Exception</a></li>
<li><a href="explicit.html">Explicit</a></li>
<li><a href="ignore.html">Ignore</a></li>
<li><a href="maxtime.html">Maxtime</a></li>
<li><a href="pairwise.html">Pairwise</a></li>
<li><a href="platform.html">Platform</a></li>
<li><a href="property.html">Property</a></li>
<li><a href="random.html">Random</a></li>
<li><a href="range.html">Range</a></li>
<li><a href="repeat.html">Repeat</a></li>
<li><a href="requiredAddin.html">RequiredAddin</a></li>
<li><a href="requiresMTA.html">Requires&nbsp;MTA</a></li>
<li><a href="requiresSTA.html">Requires&nbsp;STA</a></li>
<li><a href="requiresThread.html">Requires&nbsp;Thread</a></li>
<li><a href="sequential.html">Sequential</a></li>
<li><a href="setCulture.html">SetCulture</a></li>
<li><a href="setup.html">Setup</a></li>
<li><a href="setupFixture.html">SetupFixture</a></li>
<li><a href="suite.html">Suite</a></li>
<li><a href="teardown.html">Teardown</a></li>
<li><a href="test.html">Test</a></li>
<li><a href="testCase.html">TestCase</a></li>
<li><a href="testCaseSource.html">TestCaseSource</a></li>
<li><a href="testFixture.html">TestFixture</a></li>
<li><a href="fixtureSetup.html">TestFixtureSetUp</a></li>
<li><a href="fixtureTeardown.html">TestFixtureTearDown</a></li>
<li><a href="theory.html">Theory</a></li>
<li><a href="timeout.html">Timeout</a></li>
<li><a href="values.html">Values</a></li>
<li id="current"><a href="valueSource.html">ValueSource</a></li>
</ul>
<li><a href="runningTests.html">Running&nbsp;Tests</a></li>
<li><a href="extensibility.html">Extensibility</a></li>
<li><a href="releaseNotes.html">Release&nbsp;Notes</a></li>
<li><a href="samples.html">Samples</a></li>
<li><a href="license.html">License</a></li>
</ul>
</ul>
</div>
<!-- End of Submenu -->


<!-- Standard Footer for NUnit.org -->
<div id="footer">
  Copyright &copy; 2010 Charlie Poole. All Rights Reserved.
</div>
<!-- End of Footer -->

</body>
</html>
